//package com.hshx.filter;
//
//import com.alibaba.cloud.commons.lang.StringUtils;
//import com.alibaba.fastjson.JSONObject;
//import com.hshx.util.RedisUtil1;
//import org.apache.http.HttpResponse;
//import org.springframework.cloud.gateway.filter.GatewayFilterChain;
//import org.springframework.cloud.gateway.filter.GlobalFilter;
//import org.springframework.core.Ordered;
//import org.springframework.core.io.buffer.DataBuffer;
//import org.springframework.http.HttpHeaders;
//import org.springframework.http.HttpStatus;
//import org.springframework.http.server.reactive.ServerHttpResponse;
//import org.springframework.stereotype.Component;
//import org.springframework.web.server.ServerWebExchange;
//import reactor.core.publisher.Mono;
//
//import javax.annotation.Resource;
//import java.nio.charset.StandardCharsets;
//
//@Component
//public class MyFilter2 implements GlobalFilter, Ordered {
//    @Resource
//    private RedisUtil1 redisUtil1;
//
//    @Override
//    public int getOrder() {
//        return 2;
//    }
//
//    @Override
//    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
//        ServerHttpResponse response = exchange.getResponse();
//        String token = exchange.getRequest().getHeaders().getFirst("token");
//        System.out.println("filter2:"+token);
//        if(StringUtils.isEmpty(token)){
//            String redirectUrl = "http://localhost:90/login.html";
//            response.getHeaders()
//                    .set(HttpHeaders.LOCATION, redirectUrl);
//            //303状态码表示由于请求对应的资源存在着另一个URI，应使用GET方法定向获取请求的资源（重定向）
//            response.setStatusCode(HttpStatus.SEE_OTHER);
//            response.getHeaders().add("Content-Type", "text/plain;charset=UTF-8");
////            response.
//            System.out.println("MyFilter2工作中");
////            HttpResponse response1=(HttpResponse) response;
////            response1.sendRedirect("https://www.baidu.com");
//            return response.setComplete();
////            return chain.filter(exchange);
//        }
////        Object obj=redisUtil1.get(token);
////        if(obj==null){
////          String redirectUrl = "http://localhost:90/login.html";
////            response.getHeaders()
////                    .set(HttpHeaders.LOCATION, redirectUrl);
////            //303状态码表示由于请求对应的资源存在着另一个URI，应使用GET方法定向获取请求的资源（重定向）
////            response.setStatusCode(HttpStatus.SEE_OTHER);
////            response.getHeaders().add("Content-Type", "text/plain;charset=UTF-8");
//////            response.
////            System.out.println("MyFilter2工作中");
//////            HttpResponse response1=(HttpResponse) response;
//////            response1.sendRedirect("https://www.baidu.com");
////            return response.setComplete();
//////            return chain.filter(exchange);
////        }
//        System.out.println("MyFilter2执行........");
//        return chain.filter(exchange);
//    }
//}
